package com.company.woye.login;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.company.woye.MyApplication;
import com.company.woye.R;
import com.company.woye.base.BaseActivity;
import com.company.woye.utils.SharedPreferenceUtils;
import com.company.woye.utils.Toaster;

import butterknife.BindView;
import butterknife.OnClick;

public class IPSettingActivity extends BaseActivity {
    @BindView(R.id.tv_top_subject)
    TextView tvTopSubject;
    @BindView(R.id.ed_agv)
    EditText edAgv;
    @BindView(R.id.ed_wms)
    EditText edWms;
    @BindView(R.id.ed_api)
    EditText edApi;
    @BindView(R.id.ed_mes)
    EditText edMes;
    @BindView(R.id.ed_cut)
    EditText edCut;
    @BindView(R.id.ed_cloth)
    EditText edCloth;
    @BindView(R.id.et_left_gongwei)
    EditText leftGongWei;
    @BindView(R.id.et_right_gongwei)
    EditText rightGongWei;
    @BindView(R.id.rb_left)
    RadioButton rbLeft;
    @BindView(R.id.rb_right)
    RadioButton rbRight;


    MyApplication mApp;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.ll_include)
    LinearLayout llInclude;
    @BindView(R.id.et_songbu_gongwei)
    EditText etSongbuGongwei;
    @BindView(R.id.rg_checkout)
    RadioGroup rgCheckout;
    @BindView(R.id.tv_commit)
    TextView tvCommit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setLayoutId() {
        return R.layout.activity_ip_setting;
    }

    @Override
    public void initView() {
        tvTopSubject.setText("服务设定");
        mApp = (MyApplication) getApplication();
        edWms.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlWms", ""));
        edAgv.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlAgv", ""));
        edMes.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlMes", ""));
        edApi.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlApi", ""));
        edCut.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlCut", ""));
        edCloth.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "UrlCloth", ""));
        leftGongWei.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "leftGongWei", ""));
        rightGongWei.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "rightGongWei", ""));
        etSongbuGongwei.setText((String) SharedPreferenceUtils.getData(sharedPreferences, "songbuGongWei", ""));
        if (((String) SharedPreferenceUtils.getData(sharedPreferences, "nowGongWei", "0")).equals("0")) {
            rbLeft.setChecked(true);
        } else {
            rbRight.setChecked(true);
        }
    }

    @OnClick({R.id.iv_back, R.id.tv_commit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_commit:
                String UrlApi = edApi.getText().toString().trim();
                String UrlAgv = edAgv.getText().toString().trim();
                String UrlMes = edMes.getText().toString().trim();
                String UrlCloth = edCloth.getText().toString().trim();
                String UrlWms = edWms.getText().toString().trim();
                String UrlCut = edCut.getText().toString().trim();
                String songbuGongWei = etSongbuGongwei.getText().toString().trim();
                String mLeftGongWei = leftGongWei.getText().toString().trim();
                String mRightGongWei = rightGongWei.getText().toString().trim();
                String nowGongWei = rbLeft.isChecked() ? "0" : "1";
                if (!TextUtils.isEmpty(UrlMes)) {
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlApi", UrlApi);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlAgv", UrlAgv);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlMes", UrlMes);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlCloth", UrlCloth);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlWms", UrlWms);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlCut", UrlCut);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlCloth", UrlCloth);
                    SharedPreferenceUtils.putData(sharedPreferences, "UrlWms", UrlWms);
                    SharedPreferenceUtils.putData(sharedPreferences, "leftGongWei", mLeftGongWei);
                    SharedPreferenceUtils.putData(sharedPreferences, "rightGongWei", mRightGongWei);
                    SharedPreferenceUtils.putData(sharedPreferences, "nowGongWei", nowGongWei);
                    SharedPreferenceUtils.putData(sharedPreferences, "songbuGongWei", songbuGongWei);
                    finish();
                } else {
                    Toaster.showLong(IPSettingActivity.this, "请输入UrlMes");
                }
                break;
        }
    }
}